import {Vue, Component } from 'vue-property-decorator';
import UpImag from './_components/upfile.vue';
import AdSelect from './_components/select.vue'
import {postUpBanner,postMyCard} from '@/request/actions'

type BaseImgPaths = Array<string>;


@Component({
    components:{
        UpImag,
        AdSelect
    }
})
export default class extends Vue {
  
    salonId:string|number = '';
    selectlist:Array<any> = [];
    list:Array<any> = [];
    images:Array<any> = [];
    cardIds:Array<any> = [];


    getSelectGood(d:any){
        console.log(d)

       let {idx,cardId} = d;

       this.cardIds[idx] = cardId;

       
    }
   
    getImages(o:any){
        let {idx,path} = o;
        this.images[idx] = path;
        

        console.log(this.images)
     
    }
    
    handleSubmit(){
        let list:Array<any> = [];
        let salonId = this.salonId;
        let notImgIdx = 0;
        
        this.images.forEach((image,idx)=>{

            if(image.length){
               
                list.push({
                    image,
                    url:this.cardIds[idx] || ''
                })
            }

            
        })




      
        if(list.length == 0){

            return uni.showToast({
                title:"请上传至少一张活动图片",
                icon:'none'
            })

        } 
        postUpBanner({list,salonId}).then((r:any)=>{
            let {data:res} = r;
            if(res.status == 200){
                uni.showModal({
                    content:'店铺广告添加成功',
                    showCancel:false,
                    success:(res:any)=>{
                        uni.navigateBack();
                    }
                })
            }
        })
    }
    onLoad(query:any){
        this.salonId = query.salonId;
      

        postMyCard({salonId:this.salonId}).then((r:any)=>{

            let {data:res} = r;
            if(res.status == 200){
                this.list = res.data;
                
                
            }

        })
    }
}